#ifndef PC_COMM_H
#define PC_COMM_H

#include "bsp_usart.h"

#define SOF_ADDR            0       //帧头地址
#define FRAME_HEADER 		0xA5    //帧头多项式
#define LEN_FRAME_HEADER 	2	    //帧头长度
#define	LEN_TX_DATA 		15	    //发送数据段长度
#define	LEN_RX_DATA 		14	    //接收数据段长度
#define	LEN_FRAME_TAILER 	2	    //帧尾长度
#define	LEN_TX_PACKET		19	    //发送包长度
#define	LEN_RX_PACKET	    18	    //接收包长度

#pragma pack(1)
typedef enum
{
    NO_FIRE = 0,
    SINGLE_FIRE = 1,
} Fire_Mode_e;

typedef enum
{
    NORMOL_FIRE = 0,
    SMALL_FIRE = 1,
    BIG_FIRE = 2,
} Fire_State_e;

typedef enum
{   
    NO_AUTO = 0,
    IS_AUTO = 1,
} Auto_Fire_Flag_e;

typedef enum
{
    COLOR_NONE = 0,
    COLOR_BLUE = 1,
    COLOR_RED = 2,
} Enemy_Color_e;

typedef __packed struct
{
	uint8_t  	sof;			//项头多项式
	uint8_t  	crc8;			//CRC8校验码
} frame_header_t;

typedef __packed struct 
{
	uint16_t crc16;				//CRC16校验码
} frame_tailer_t;

typedef struct
{
    Fire_Mode_e fire;           //开火指令
    float shoot_yaw;            //最终云台yaw角度
    float shoot_pitch;          //最终云台pitch角度
    float shoot_speed_avg;
    uint8_t food;               //狗粮
} rx_data_t;

typedef struct
{
    float curr_yaw;                 //当前云台yaw角度
    float curr_pitch;               //当前云台pitch角度
    float shoot_speed;              //当前子弹速度
    Fire_State_e fire_state;        //当前状态，0：正常，1：大符，2：小符
    Auto_Fire_Flag_e IsAuotoAim;    //是否自瞄
    Enemy_Color_e enemy_color;      //敌方颜色
} tx_data_t;

typedef struct
{
    frame_header_t frame_header;
    rx_data_t rx_data;
    frame_tailer_t frame_tailer;
} PC_Recv_s;

typedef struct
{
    frame_header_t	 	frame_header;	
	tx_data_t	  		tx_data;	
	frame_tailer_t 		frame_tailer;	
} PC_Send_s;
#pragma pack()

void PCVisionInit(void);

void PCVisionSend(void);

void PCVisionSetFlag(Fire_State_e fire_state, 
                     Auto_Fire_Flag_e auto_flag, 
                     Enemy_Color_e enemy_color);

void PCVisionSetAttitude(float yaw, float pitch, float shoot_speed);

uint8_t PCVisionDecode(PC_Recv_s* recv_data, uint8_t* buf);
#endif
